<template>
  <div class="content" style="background-color: #fff;height: 100%">
    我的分享
    <div>
      <el-collapse v-model="shareFiles" style="padding: 20px;font-size: 20px">
        <el-collapse-item style="padding-left: 20px;"  v-for="(share,index) in this.shareFiles" :key="share.id" :title="(index+1)+'.标题：'+share.title" :name="share.id">
          <div style="padding-left: 50px">

            <div><span style="font-weight: bolder">描述：</span>{{share.description == null ? '暂无描述' : share.description}}</div>
            <div><span style="font-weight: bolder">密码：</span>{{share.password == '' ? '无需密码' :share.password}}</div>
            <div><span style="font-weight: bolder">链接：</span>
              <el-link type="primary" :href="'http://127.0.0.1/#/share?path='+share.path" target="_blank">
                http://127.0.0.1/#/share?path={{share.path}}
              </el-link>
            </div>
            <div><span style="font-weight: bolder">创建时间：</span>{{share.createTime}}</div>
            <div><span style="font-weight: bolder">有效时间：</span>{{share.endTime}}</div>
            <div><el-button type="primary" @click="copyMessage('分享文件：'+share.title+'【http://127.0.0.1/#/share?path='+share.path+'】密码：'+share.password+' 快来查看下载吧!')">复制链接</el-button>
              <el-button :disabled="share.flag != '1' " @click="cancelShare(share.id)" type="danger">取消分享</el-button>
            </div>

          </div>

        </el-collapse-item>
      </el-collapse>
    </div>

  </div>
</template>

<script>
import {allShare,saveShare,deleteShareId} from "@/api/disk/share";
import {mapGetters,mapState} from 'vuex';
export default {
  name: "share",
  data(){
    return{
      activeNames: [],
      shareFiles:[{
        path:""
      }]
    }
  },
  created() {
    this.getData();
  },
  methods:{
    cancelShare(id){
      this.$confirm('是否确认取消分享该文件?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        deleteShareId(Object.assign({
          id:id
        })).then(re=>{
          if (re.data.code == 0){
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getData();
          }
        })

      })

    },
    copyMessage(msg){
      var _this = this;

      this.$copyText(msg).then(function (e) {
        _this.$message.success("复制成功,快去分享给你的好友吧!")
      }, function (e) {
        _this.$message.error('Can not copy')
      })
    },
    getData(){
      allShare().then(data=>{
        this.shareFiles = data.data.data;
        console.log(this.shareFiles)
      }).catch(()=>{
        this.$message({
          message: '获取失败,请稍后再试!',
          type: 'error'
        });
      })
    }
  }
}
</script>

<style scoped>

</style>
